<?php

use yii\helpers\Html;
use yii\widgets\DetailView;

$url_dict = parse_url(Yii::$app->request->referrer);
$header_show = true;
if (strpos($url_dict['query'], 'r=') !== false && strpos($url_dict['query'], 'patient') !== false && strpos($url_dict['query'], 'receive') !== false) {
    $header_show = false;
}

$recall_html = "";
if (null != $model->recalls && count($model->recalls) > 0) {
    $recall_html .= "<table class='table table-bordered'><tr><td>回访人</td><td>类型</td><td>时间</td><td>内容</td></tr>";
    foreach ($model->recalls as $r) {
        $recall_html .= "<tr><td>{$r->username}</td><td>{$r->kinds}</td><td>{$r->createtime}</td><td>{$r->content}</td></tr>";
    }
    $recall_html .= "</table>";
}

$table_tr = [
    'id',
    'name',
    'sex',
    'age',
    'address',
    'telphone',
    'istoday',
    ['label' => '预约科室', 'value' => $model->department_name],
    ['label' => '预约病种', 'value' => $model->disease_name],
    'order_number',
    'qq',
    'wechat',
    'workgroup',
    ['label' => '咨询方式', 'value' => $model->communication_name],
    ['label' => '来源渠道', 'value' => $model->comeway_name],
    ['label' => '咨询人', 'value' => $model->username],
    'createtime',
    'status',
    ['label' => '预约医生', 'value' => $model->order_doctor_name],
    ['label' => '接诊医生', 'value' => $model->operate_doctor_name],
    'order_time',
    'arrive_time',
    'forever_id',
    'keyword',
    ['label' => '回访记录', 'format' => 'raw', 'value' => $recall_html],
    'condition_log:ntext',
    'talk_log:raw',
    'edit_log:raw',
];

/* @var $this yii\web\View */
/* @var $model app\models\Patient */

$this->title = $model->name;
$this->params['breadcrumbs'][] = ['label' => '患者信息列表', 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
\yii\web\YiiAsset::register($this);
?>
<div class="patient-view" style="width:800px;margin:0 auto;">

    <h1 style="text-align: center;"><?= Html::encode($this->title) ?></h1>

    <p>
        <?= Html::a('修改', ['update', 'id' => $model->id], ['class' => 'btn btn-primary modify_button']) ?>
        <?php if (Yii::$app->user->identity->jobname == '超级管理员') {
            Html::a('删除', ['delete', 'id' => $model->id], [
                'class' => 'btn btn-danger',
                'data' => [
                    'confirm' => 'Are you sure you want to delete this item?',
                    'method' => 'post',
                ],
            ]);
        } ?>
    </p>

    <?= DetailView::widget([
        'model' => $model,
        'attributes' => $table_tr,
    ]) ?>

</div>

<script type="text/javascript">
    <?php if ($header_show == false) { ?>
        $('#page_header').hide();
        $('ul.breadcrumb').hide();
        $('a.modify_button').hide();
    <?php } ?>

    $('table#w0 th:first').attr('width', '120');
</script>